/**
 * 
 */
package com.pocketsweet.model;

import java.util.List;

import com.avos.avoscloud.AVClassName;
import com.avos.avoscloud.AVFile;
import com.avos.avoscloud.AVObject;
import com.pocketsweet.service.UserService;

/**
 * @author hantian
 * 
 */
@AVClassName("MLGallery")
public class MLGallery extends AVObject {
	public static final String NAME = "name";
	public static final String INTRO = "intro";
	public static final String IMAGES = "images";
	public static final String BELONG_TO = "belong_to";

	public MLGallery() {
		setIntro("暂无介绍");
		setName("default gallery");
	}

	// //////////////////////////////////////////
	// 外键 相册所有者
	// //////////////////////////////////////////
	public MLUser getBelongTo() {
		return (MLUser) super.getAVUser(BELONG_TO);
	}

	public void setBelongTo(MLUser user) {
		super.put(BELONG_TO, user);
	}

	// //////////////////////////////////////////
	// get
	// //////////////////////////////////////////
	public String getName() {
		return super.getString(NAME);
	}

	public void setName(String value) {
		super.put(NAME, value);
	}

	public String getIntro() {
		return super.getString(INTRO);
	}

	public void setIntro(String value) {
		super.put(INTRO, value);
	}

	@SuppressWarnings("unchecked")
	public List<AVFile> getImages() {
		return (List<AVFile>) super.getList(IMAGES);
	}

	public void setImage(List<AVFile> value) {
		super.put(IMAGES, value);
	}

	public void addImages(List<AVFile> value) {
		addAllUnique(IMAGES, value);
	}

	public void removeImage(int position) {
		List<AVFile> imgs = getImages();
		imgs.remove(position);
		this.remove("images");
		addAllUnique(IMAGES, imgs);
		this.saveInBackground();
	}
}
